package com.example.demo.service.equipment;

import com.example.demo.domain.equipment.Plan;
import com.example.demo.domain.equipment.repository.PlanRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlanService {
    @Autowired
    private PlanRepository planRepository;
    /**
     * @Description: 获取全部未审批列表
     * @Param:  无
     * @return:  全部未审批列表
     * @Author: wangze
     */
    public List<Plan> getPlan(String planId) {
        return planRepository.getAllByPlanId(planId);
    }

    public Plan addplan(Plan p) {
        return planRepository.save(p);
    }

    public Plan getPlanbyTicketidMatched(Integer id) {
        return planRepository.findByTicketId(id);
    }

    public Plan editPlan(Plan p){
        Plan plan = planRepository.findByTicketId(p.getTicketId());
        plan.setPurchaseItem(p.getPurchaseItem());
        plan.setExpectSglPrice(p.getExpectSglPrice());
        plan.setPurchaseNum(p.getPurchaseNum());
        plan.setPurchaseUnit(p.getPurchaseUnit());
        plan.setExpectPrice(p.getExpectPrice());
        plan.setPurchaseContract(p.getPurchaseContract());
        plan.setUtdPurchaseNum(p.getUtdPurchaseNum());
        plan.setPurchaseStatus(p.getPurchaseStatus());
        return planRepository.save(plan);
    }

    public void deletePlan(Integer id){
        planRepository.deleteById(id);
    }
}
